home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / Requester.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.8 KB  |  93 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataInputStream;
  5. import java.io.DataOutputStream;
  6. import java.io.FilterOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.OutputStream;
  10. import symjava.sql.SQLException;
  11.  
  12. public abstract class Requester {
  13.    String _reqDelim;
  14.    MPlex _mplex;
  15.    IO _io;
  16.    ClientSession _sess;
  17.  
  18.    public Requester(ClientSession sess) {
  19.       this._sess = sess;
  20.       this._mplex = this._sess._mplex;
  21.       this._reqDelim = new String(",");
  22.    }
  23.  
  24.    public ClientSession getSession() {
  25.       return this._sess;
  26.    }
  27.  
  28.    protected IO getIO() throws NetException, SQLException {
  29.       return this._mplex.getIO();
  30.    }
  31.  
  32.    protected void releaseIO() {
  33.       this._mplex.releaseIO(this._io);
  34.    }
  35.  
  36.    protected void onObjectError(ServerObject obj) throws SQLException {
  37.       if (obj.getType() == 49) {
  38.          throw ((NetError)obj).toSQLException();
  39.       } else if (obj.getType() == 68) {
  40.          throw ((ExceptionList)obj).getSQLException();
  41.       } else {
  42.          throw new SQLException("SCALE object stream error.");
  43.       }
  44.    }
  45.  
  46.    public void execute() throws SQLException {
  47.       ByteArrayOutputStream bytestream = new ByteArrayOutputStream(512);
  48.       DataOutputStream outstream = new DataOutputStream(bytestream);
  49.  
  50.       try {
  51.          try {
  52.             this._io = this.getIO();
  53.          } catch (NetException e) {
  54.             throw new SQLException(((Throwable)e).getMessage());
  55.          }
  56.  
  57.          InputStream e = this._io.getInputStream();
  58.          synchronized(e){}
  59.  
  60.          try {
  61.             outstream.writeByte(56);
  62.             outstream.writeShort(0);
  63.             this.writeRequest(outstream);
  64.             EOT eot = new EOT();
  65.             eot.write(outstream);
  66.             byte[] b = bytestream.toByteArray();
  67.             OutputStream out = this._io.getOutputStream();
  68.             out.write(b);
  69.             ((FilterOutputStream)outstream).close();
  70.             SocketIS inStrm = (SocketIS)this._io.getInputStream();
  71.             inStrm.reset();
  72.             DataInputStream in = new DataInputStream(this._io.getInputStream());
  73.             this.readResults(in);
  74.             this.releaseIO();
  75.          } catch (Throwable var15) {
  76.             throw var15;
  77.          }
  78.  
  79.       } catch (IOException var17) {
  80.          this._mplex.connectionLost();
  81.          throw new SQLServerConnException();
  82.       } catch (ErrorException var18) {
  83.          throw new SQLException("SCALE Server error");
  84.       } catch (NetException e) {
  85.          throw new SQLException("SCALE net error( " + ((Throwable)e).getMessage() + " )");
  86.       }
  87.    }
  88.  
  89.    protected abstract void readResults(DataInputStream var1) throws IOException, ErrorException, SQLException;
  90.  
  91.    protected abstract void writeRequest(DataOutputStream var1) throws IOException;
  92. }
  93.